package com.facemox.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.facemox.bean.FaceExecuteLog;
import com.facemox.bean.ServerMonitor;
import com.facemox.bean.Statistic;

public interface StatisticMapper {
    
    // 统计接口总数
    @Select("select count(*) from face_info")
    int getFaceCount();
    
    // 统计接口执行的次数
    @Select("select count(*) from face_statistic")
    int getFaceExecuteCount();
    
    // 插入一条接口执行的数据
    @Insert("INSERT INTO face_statistic(face_id,module_id,authentication_id) values(#{faceId},#{moduleId},#{authenticationId})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="statisticId",keyColumn="statistic_id")
    int addFaceStatisticItem(Statistic statistic);
    
    // 插入一条服务监控的数据
    @Insert("INSERT INTO face_server_monitor(server_name,server_ip,remark) values(#{serverName},#{serverIp},#{remark})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="serverId",keyColumn="server_id")
    int addServerMonitor(ServerMonitor serverMonitor);
    
    // 查询所有的服务监控
    @Select("select * from face_server_monitor")
    @Results({
        @Result(column = "server_id",property = "serverId"),
        @Result(column = "server_name",property = "serverName"),
        @Result(column = "server_ip",property = "serverIp"),
        @Result(column = "remark",property = "remark")
    })
    List<ServerMonitor> getServerMonitor();
    
    // 查询所有服务监测数量
    @Select("select count(*) from face_server_monitor")
    int getServerMonitorCount();
    
    // 查询链路执行总数
    @Select("select count(*) from face_link_execute_log")
    int getFaceLinkExecuteCount();
    
 // 查询链路执行总数
    @Select("select count(*) from face_link")
    int getFaceLinkCount();
    
    // 插入一条接口执行的日志
    @Insert("INSERT INTO face_execute_log(face_id,module_id,authentication_id,authentication_type,request_body,response_body,create_time) values(#{faceId},#{moduleId},#{authenticationId},#{authenticationType},#{requestBody},#{responseBody},#{createTime})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="logId",keyColumn="log_id")
    int addFaceExecutelog(FaceExecuteLog faceExecuteLog);
    
}
